
const path = require("path");

const json5 = require('json5');
const yaml = require('yamljs');
const toml = require('toml');

const HtmlWebpackPlugin = require('html-webpack-plugin');

const currentDir = __dirname;

// __webpack_public_path__ = 'https://cdn.example.com';

module.exports = {
  entry:{
     app: path.join(currentDir,'src/index.js'),
  },
  output:{
    filename:'[name].[contenthash].js',
    path: path.join(currentDir , '/dist'),
    clean :true,
  },

  devtool:"inline-source-map",

  devServer:{
    // open:true,
    // static:path.join(currentDir,'/dist'),
    // contentDocument:path.join(currentDir,'/dist'),
    port:8081,
    // contentDocument:path.join(currentDir,'/dist'),
  },
  mode: "development",
  optimization:{
    usedExports:true,
  },


  module:{
    rules:[
      {
        test:/\.css$/,
        use:['style-loader','css-loader'],
      },
      {
        test:/\.ts$/,
        use:'ts-loader'
      },
      {
        test:/\.(png|jpg|jpeg|svg|gif)$/i,
        type:"asset/resource"
      },
      {
        test: /\.(ttf|otf|woff|woff2|eot)$/i,
        type:'asset/resource'
      },
      {
        test:/\.(csv|tsv)$/i,
        use:"csv-loader"
      },
      {
        test:/\.xml$/i,
        use:'xml-loader'
      },
      {
        test:/\.toml$/i,
        type:"json",
        parser:{
          parse:toml.parse,
        }
      },
      {
        test:/\.json5$/i,
        type:"json",
        parser:{
          parse:json5.parse,
        }
      },
      {
        test:/\.yaml$/i,
        type:"json",
        parser:{
          parse:yaml.parse,
        }
      }
    ],
  },
  plugins:[
    new HtmlWebpackPlugin({
      title:"output manager"
    }),
  ],

};
